import { requestClient } from '#/api/request';

export namespace LandingCompanyApi {
  export type LandingCompanyStatus = 'active' | 'inactive';

  export interface LandingCompanyRecord {
    id: number;
    name: string;
    short_name: string;
    code: string;
    tax_number: string;
    address: string;
    contact_person: string;
    phone: string;
    email: string;
    status: LandingCompanyStatus;
    billing_categories: string[];
    remark: string;
    bank_name: string;
    account_number: string;
    balance: number;
    created_at: string;
    updated_at: string;
  }

  export interface UpsertLandingCompanyPayload {
    name: string;
    short_name: string;
    code: string;
    tax_number: string;
    address: string;
    contact_person: string;
    phone: string;
    email: string;
    status: LandingCompanyStatus;
    billing_categories: string[];
    remark: string;
    bank_name: string;
    account_number: string;
    balance: number;
  }

  export interface LandingCompanyListResponse {
    items: LandingCompanyRecord[];
    total: number;
  }
}

export async function getLandingCompaniesApi() {
  return requestClient.get<LandingCompanyApi.LandingCompanyListResponse>('/api/admin/landing-companies');
}

export async function createLandingCompanyApi(payload: LandingCompanyApi.UpsertLandingCompanyPayload) {
  return requestClient.post<LandingCompanyApi.LandingCompanyRecord>('/api/admin/landing-companies', payload);
}

export async function updateLandingCompanyApi(id: number, payload: LandingCompanyApi.UpsertLandingCompanyPayload) {
  return requestClient.put<LandingCompanyApi.LandingCompanyRecord>(`/api/admin/landing-companies/${id}`, payload);
}
